﻿Public Class FormNgAdd
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Dim oper_u As String
    Dim dtProcedure As New DataTable
    Public b_gt_sys_id As String
    Public oper_type As String
    Public oper_type_name As String
    Public type_value As String
    Public batch_no As String
    Public assist_marker As String
    Public picking_num As String
    Public ng_num As String
    Dim objReasonMst As New clsReasonMst
    Dim objGtNgDetails As New clsGtNgDetails

    Private Sub FormNgAdd_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        oper_u = GetIniFile("LOGIN", "user", "", g_szInitFileName)
        txt_oper_type_name.Text = oper_type_name
        txt_type_value.Text = type_value
        txt_batch_no.Text = batch_no
        txt_assist_marker.Text = assist_marker
        lbl_gt_sys_id.Text = b_gt_sys_id
        dtProcedure.Columns.Add("name")
        dtProcedure.Columns.Add("val")
        If oper_type.Equals("0") Then
            dtProcedure.Rows.Add("抛丸(骨架板)", "0")
            dtProcedure.Rows.Add("校平", "1")
            dtProcedure.Rows.Add("喷砂清洗(骨架板)", "2")
            dtProcedure.Rows.Add("六工位", "3")
        End If
        If oper_type.Equals("1") Then
            dtProcedure.Rows.Add("抛丸(法兰板)", "0")
            dtProcedure.Rows.Add("喷砂清洗(法兰板)", "1")
            dtProcedure.Rows.Add("三工位", "2")
        End If
        cmb_procedure.DisplayMember = "name"
        cmb_procedure.ValueMember = "val"
        cmb_procedure.DataSource = dtProcedure
        cmb_procedure.SelectedIndex = 0
    End Sub

    Private Sub cmb_procedure_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmb_procedure.SelectedIndexChanged
        If oper_type.Equals("0") Then
            objReasonMst.setMstChkList(chkNg_Reason, "gjb", cmb_procedure.SelectedValue)
        End If
        If oper_type.Equals("1") Then
            objReasonMst.setMstChkList(chkNg_Reason, "flb", cmb_procedure.SelectedValue)
        End If
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If String.IsNullOrEmpty(oper_u) Then
            MsgBox("请切换用户进行登录！")
            Exit Sub
        End If
        If Integer.Parse(txt_num.Value) > 0 Then
            Dim integer_picking_num As Integer = Integer.Parse(picking_num)
            Dim integer_ng_num As Integer = Integer.Parse(ng_num)
            Dim operable_num As Integer = integer_picking_num - integer_ng_num
            If Integer.Parse(txt_num.Value) <= operable_num Then
                Dim chklstChecked As Boolean = False
                For i As Integer = 0 To chkNg_Reason.Items.Count - 1
                    If chkNg_Reason.Items(i).CheckState = CheckState.Checked Then
                        chklstChecked = True
                    End If
                Next
                If chklstChecked = False Then
                    MsgBox("请选择不合格原因！")
                    chkNg_Reason.Select()
                    Exit Sub
                End If
                Dim ng_reason As String = String.Empty
                For i As Integer = 0 To chkNg_Reason.Items.Count - 1
                    If chkNg_Reason.Items(i).CheckState = CheckState.Checked Then
                        ng_reason &= chkNg_Reason.Items(i).Value & "/"
                    End If
                Next
                ng_reason = ng_reason.Substring(0, ng_reason.Length - 1)
                Dim en As New entity_gt_ng_details
                en.procedure_No = cmb_procedure.SelectedValue
                en.ng_num = Integer.Parse(txt_num.Value)
                en.ng_reason = ng_reason
                en.validity = "1"
                en.oper = oper_u
                en.b_gt_sys_id = Integer.Parse(lbl_gt_sys_id.Text)
                Dim rtn As Integer = objGtNgDetails.save(en)
                If rtn <> -2 Then
                    MsgBox("保存成功")
                    CType(Owner, FormCheck).setDgvData()
                    Close()
                Else
                    MsgBox("保存失败")
                End If
            Else
                MsgBox("不合格数量大于可操作数量，可操作数量为：" & operable_num.ToString())
            End If
        Else
            MsgBox("不合格数量需>0")
        End If
    End Sub

    Private Sub txt_num_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_num.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub

End Class

Public Class entity_gt_ng_details
    Public procedure_No As String   ' 工序
    Public ng_num As Integer   ' 不合格数量
    Public ng_reason As String  '原因
    Public b_gt_sys_id As Integer  '关联ID
    Public oper As String   '操作员
    Public validity As String  '有效性
End Class